2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
8 namespace SuperPolarity
10 static class ActorManager
12 static List<Actor> Actors;
16 Actors = new List<Actor>();
19 static public void CheckIn(Actor actor)
24 static public void CheckOut(Actor actor)
29 static public void Update(GameTime gameTime)
32 foreach (Actor actor in Actors)
34 actor.Update(gameTime);
38 static public void Draw(SpriteBatch spriteBatch)
40 foreach (Actor actor in Actors)
42 actor.Draw(spriteBatch);
46 static void CheckActors()
49 foreach (Actor actor in Actors)
52 foreach (Actor other in Actors.Skip(i))
54 CheckCollision(actor, other);
56 if (actor.GetType().IsSubclassOf(typeof(Ship)) && other.GetType().IsSubclassOf(typeof(Ship)))
58 CheckMagnetism((Ship)actor, (Ship)other);
64 static void CheckCollision(Actor actor, Actor other)
69 static void CheckMagnetism(Ship actor, Ship other)
71 if (actor.CurrentPolarity != Ship.Polarity.Neutral && other.CurrentPolarity != Ship.Polarity.Neutral)
73 var dy = other.Position.Y - actor.Position.Y;
74 var dx = other.Position.X - actor.Position.X;
75 var linearDistance = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
76 var angle = (float) Math.Atan2(dy, dx);
78 if (linearDistance < actor.MagneticRadius || linearDistance < other.MagneticRadius)
80 actor.Magnetize(other, (float)linearDistance, angle);
81 other.Magnetize(actor, (float)linearDistance, 90 - angle);